Skip to content

fix: defensively release virtualDisplay before creation#78

Merged
SamuelBrucksch merged 2 commits into
Iternio-Planning-AB:masterfrom
AntonHakansson:fix/release-virtual-display-defensively
May 18, 2026
Merged

fix: defensively release virtualDisplay before creation#78
SamuelBrucksch merged 2 commits into
Iternio-Planning-AB:masterfrom
AntonHakansson:fix/release-virtual-display-defensively

Conversation

@AntonHakansson

Copy link
Copy Markdown
Contributor

In pathological cases, onSurfaceDestroyed is never called and the cleanup in onSurfaceDestroyed (virtualDisplay?.release()) never runs. Each call to onSurfaceAvailable orphans the previous VirtualDisplay that remains alive consuming framebuffers, but with no reference to release it.

This is likely a bug higher up in the stack (CarAppActivity), but good to protect against it.

I encountered this issue when running ABRP on Android Automotive, repeated onSurfaceAvailable callbacks without corresponding onSurfaceDestroyed callbacks cause VirtualDisplay instances to leak in VirtualRenderer.kt. Each leaked virtual display exhausts GPU resources and surfaceflinger eventually crashes when it tries to create a texture with:

Failed to create a valid texture. [0xb400007ad86b25f0]:[2640,1416] isProtected:0 isWriteable:0 format:1
Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 1153 (RenderEngine), pid 1032 (surfaceflinger)

Reproduced with something like:

   for i in $(seq 1 100); do
       adb shell am start -n com.iternio.abrpapp/androidx.car.app.activity.CarAppActivity \
           -a android.intent.action.MAIN -c android.intent.category.LAUNCHER \
           --activity-single-top
       sleep 1
   done

and monitored increasing virtual displays with

adb shell dumpsys display | grep -c "AutoPlayRoot"

AntonHakansson and others added 2 commits May 5, 2026 08:11
In pathological cases, `onSurfaceDestroyed` is never called and the
cleanup in `onSurfaceDestroyed` (`virtualDisplay?.release()`) never
runs. Each call to `onSurfaceAvailable` orphans the previous
`VirtualDisplay` that remains alive consuming framebuffers, but with
no reference to release it.
@github-actions

github-actions Bot commented May 7, 2026

Copy link
Copy Markdown
Contributor

No significant issues found.

@SamuelBrucksch

Copy link
Copy Markdown
Contributor

Thanks for checking and opening this PR. We will have a look.

@SamuelBrucksch

Copy link
Copy Markdown
Contributor

This seems to be a fun quirk of an Automotive OEM adjustment. It properly calls the onSurfaceDestroyed on Android Auto and the AVD. Thanks for checking. We will release a new version soon, so it can be used in ABRP too.

@SamuelBrucksch SamuelBrucksch merged commit 749af34 into Iternio-Planning-AB:master May 18, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants